package com.tcm.smarthealth.controller;

import com.tcm.smarthealth.common.ApiResponse;
import com.tcm.smarthealth.dto.UserLoginRequest;
import com.tcm.smarthealth.dto.UserLoginResponse;
import com.tcm.smarthealth.dto.UserRegisterRequest;
import com.tcm.smarthealth.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Tag(name = "用户认证", description = "用户注册、登录相关接口")
@RestController
@RequestMapping("/api/v1/auth")
@Validated
public class AuthController {

    private final UserService userService;

    public AuthController(UserService userService) {
        this.userService = userService;
    }

    @Operation(summary = "用户注册")
    @PostMapping("/register")
    public ApiResponse<Void> register(@Valid @RequestBody UserRegisterRequest request) {
        userService.register(request);
        return ApiResponse.success("注册成功", null);
    }

    @Operation(summary = "用户登录")
    @PostMapping("/login")
    public ApiResponse<UserLoginResponse> login(@Valid @RequestBody UserLoginRequest request) {
        UserLoginResponse response = userService.login(request);
        return ApiResponse.success(response);
    }
}

